package leetcode.test;

class Solution {
    public int search(int[] nums, int target) {
       int left = 0;
        int right=nums.length-1;
        int mid = 0;
        while(left<=right){
            mid = left+(right-left)/2;
            if(target>nums[mid]){
                left = mid+1;
            }else if(target<nums[mid]){
                right = mid-1;
            }else {
                return mid;
            }
        }
        return -1;    
    }

    public static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};

        int search = new Solution().search(nums, 9);
        System.out.println(search);
    }
}